#include <iostream>
#include <UnidirectionLinkedList.hpp>

using namespace std;

class Solution
{
public:
    ListNode *deleteDuplicates(ListNode *head)
    {
        if (head == nullptr || head->next == nullptr)
            return head;
        ListNode *fakeHead = new ListNode(101, head);
        ListNode *before = fakeHead;
        ListNode *start = before->next;
        while (start != nullptr && start->next != nullptr)
        {
            if (start->next->val == start->val)
            {
                ListNode *last = start->next;
                while (last->next != nullptr && last->next->val == last->val)
                {
                    last = last->next;
                }
                // delete start-next
                before->next = last->next;
                start = before;
            }
            before = start;
            start = start->next;
        }
        return fakeHead->next;
    }
};
int main()
{
    cout << "Code82" << endl;
    Solution s;
    PrintLinkedList(s.deleteDuplicates(CreateLinkedList({1, 1, 2, 3, 3})));
    return 0;
}